from pathlib import Path
from unittest.mock import Mock
import pytest

@pytest.fixture
def store_dbpath():
    return Path(__file__).parent.absolute() / 'articles'

@pytest.fixture
def mock_store():
    content = [
        {'name': 'A puma is at large', 'category': 'nce3', 'order': 1, 'id': 0},
        {'name': 'Thirteen equals one', 'category': 'nce3', 'order': 2, 'id': 1}]
    return Mock(
        list=Mock(return_value=content))

@pytest.fixture
def mock_io():
    import queue
    inputs = queue.Queue()
    outputs = queue.Queue()
    fake_output = lambda txt: outputs.put(txt)
    fake_input = lambda: inputs.get()
    get_output = lambda: outputs.get(timeout=1)
    send_input = lambda cmd: inputs.put(cmd)
    return (fake_input, fake_output, send_input, get_output)
